package com.mss.media.controller;


import com.mss.media.dto.AddAdminDTO;
import com.mss.media.dto.AdminLoginDto;
import com.mss.media.service.IMediaAdminService;
import com.mss.media.util.ResultBody;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author runqiang
 * @since 2021-12-01
 */
@RestController
@CrossOrigin
@RequestMapping("/media-admin")
public class MediaAdminController {

    @Autowired
    private IMediaAdminService mediaAdminService;

    /**
     * 登录
     *
     * @param dto 账号密码
     * @return
     */
    @PostMapping("/login-admin")
    public ResultBody loginAdmin(@RequestBody AdminLoginDto dto) {
        return ResultBody.success(mediaAdminService.adminLogin(dto));
    }

    /**
     * 添加管理员
     *
     * @param dto 账号信息
     * @param request 请求头
     * @return 密码
     */
    @RequiresPermissions("admin:add-admin")
    @PostMapping("/add-admin")
    public ResultBody addAdmin(@RequestBody AddAdminDTO dto, HttpServletRequest request) {
        return ResultBody.success(mediaAdminService.addAdmin(dto,request));
    }

}
